package io.renren.modules.jxgk.controller;

import io.renren.RandomString;
import io.renren.common.annotation.SysLog;
import io.renren.common.exception.RRException;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.jxgk.entity.StudentInfoEntity;
import io.renren.modules.jxgk.service.StudentInfoService;
import io.renren.modules.jxgk.utils.UUidCreater;
import io.renren.modules.jxgkphone.service.StuInfoService;
import io.renren.modules.jxgkphone.entity.StudentInfo;
import io.renren.modules.pullin.service.PullOutService;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.wuwenze.poi.ExcelKit;

import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.*;


@RestController
@RequestMapping("StudentInfo/")
public class StudentInfoController {

    @Autowired
    StudentInfoService studentInfoService;
    @Autowired
    PullOutService pullOutService;
    @Autowired
    StuInfoService stuInfoService;
    UUidCreater uuid=new UUidCreater();
    @RequestMapping("Select")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<StudentInfoEntity> cse = studentInfoService.queryList(query);
        int total = studentInfoService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(cse, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }
    @RequestMapping("getStudentsByClass")
    public R getStudentsByClass(@RequestParam Map<String, Object> params){
        //查询列表数据
        List<StudentInfoEntity> cse = studentInfoService.queryList(params);

        return R.ok().put("list", cse);
    }
    @RequestMapping("getStudentInfoByClass")
    public R getStudentInfoByClass(@RequestParam Map<String, Object> params){
        //查询列表数据
        List<StudentInfoEntity> cse = studentInfoService.getStudentInfoByClass(params);

        return R.ok().put("list", cse);
    }
    @RequestMapping("/Delete")
    public R delete(@RequestBody String[] indexs){
        studentInfoService.deleteBatch(indexs);
        return R.ok();
    }
    @RequestMapping("/Insert")
    public R save(@RequestBody StudentInfoEntity ste){
        UUidCreater u=new UUidCreater();
        ste.setStudentId(u.getUUID());
        studentInfoService.save(ste);
        return R.ok();
    }
    @RequestMapping("/Info/{index}")
    public R info(@PathVariable("index") String index){
        StudentInfoEntity cse = studentInfoService.queryObject(index);
        return R.ok().put("StudentInfo", cse);
    }
    @SysLog("修改用户")
    @RequestMapping("/Update")
    public R update(@RequestBody StudentInfoEntity cse){
        studentInfoService.update(cse);
        return R.ok();
    }

    @RequestMapping("/export")
    public R export(HttpServletResponse response,String searching) {
        List<StudentInfoEntity> cse=null;
        try{
            HashMap map = new HashMap();

            map.put("searching",searching);
            cse=studentInfoService.queryList(map);
        ExcelKit.$Export(StudentInfoEntity.class, response).toExcel(cse, "用户信息");
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return R.ok().put("StudentInfo", cse);
    }



}